package com.color.admin.system.entity;


import com.color.admin.common.core.constant.Constant;
import com.color.admin.common.core.constant.ConstantData;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Set;

/**
 * @author HaiQiu
 * @date 2022/1/18
 * 基础实体公共配置
 */
@Entity
@Table(name = ConstantData.DEPT_DICT, schema = ConstantData.SOURCE)
public class SysDict extends BaseEntity implements Serializable {

    @Id
    @Column(name = "id")
    @GeneratedValue(generator = "id")
    @GenericGenerator(name = "id", strategy = "org.hibernate.id.UUIDGenerator")
    @NotEmpty(groups = update.class, message = "ID" + Constant.NOT_EMPTY)
    private String id;


    @Column(name = "code")
    @Schema(example = "sex", description = "字典码")
    @NotEmpty(message = "字典码" + Constant.NOT_EMPTY)
    @Size(min = 1, max = 100, message = "字典码长度只能在1-100个字符")
    private String code;


    @Column(name = "name")
    @Schema(example = "性别", description = "字典名称")
    @NotEmpty(message = "字典名称" + Constant.NOT_EMPTY)
    @Size(min = 1, max = 50, message = "字典名称长度只能在1-50个字符")
    private String name;


    @Column(name = "description")
    @Schema(example = "性别描述", description = "字典描述")
    @NotEmpty(message = "字典描述" + Constant.NOT_EMPTY)
    @Size(min = 1, max = 500, message = "字典描述只能在1-500个字符")
    private String description;

    @Basic
    @Column(name = "parent_id")
    @Schema(example = "0", description = "父级ID")
    private String parentId;

    @JsonIgnore
    @OneToMany(mappedBy = "dict", cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
    @Schema(hidden = true)
    private Set<SysDictDetail> dictDetails;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setDictDetails(Set<SysDictDetail> dictDetails) {
        this.dictDetails = dictDetails;
    }

    public Set<SysDictDetail> getDictDetails() {
        return dictDetails;
    }
}
